/*******************************************************************************
 * Copyright 2014 United States Government as represented by the
 * Administrator of the National Aeronautics and Space Administration.
 * All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package gov.nasa.ensemble.core.plan.resources.profile.provider;

import gov.nasa.ensemble.core.plan.resources.profile.util.ProfileAdapterFactory;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;

import org.eclipse.emf.edit.provider.ChangeNotifier;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChangeNotifier;
import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;

/**
 * This is the factory that is used to provide the interfaces needed to support Viewers.
 * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
 * The adapters also support Eclipse property sheets.
 * Note that most of the adapters are shared among multiple instances.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public class ProfileItemProviderAdapterFactory extends ProfileAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable {
	/**
	 * This keeps track of the root adapter factory that delegates to this adapter factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComposedAdapterFactory parentAdapterFactory;

	/**
	 * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IChangeNotifier changeNotifier = new ChangeNotifier();

	/**
	 * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected Collection<Object> supportedTypes = new ArrayList<Object>();

	/**
	 * This constructs an instance.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ProfileItemProviderAdapterFactory() {
		supportedTypes.add(IEditingDomainItemProvider.class);
		supportedTypes.add(IStructuredItemContentProvider.class);
		supportedTypes.add(ITreeItemContentProvider.class);
		supportedTypes.add(IItemLabelProvider.class);
		supportedTypes.add(IItemPropertySource.class);
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileEffect} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProfileEffectItemProvider profileEffectItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileEffect}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createProfileEffectAdapter() {
		if (profileEffectItemProvider == null) {
			profileEffectItemProvider = new ProfileEffectItemProvider(this);
		}

		return profileEffectItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileMember} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProfileMemberItemProvider profileMemberItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileMember}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createProfileMemberAdapter() {
		if (profileMemberItemProvider == null) {
			profileMemberItemProvider = new ProfileMemberItemProvider(this);
		}

		return profileMemberItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.ResourceProfileMember} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ResourceProfileMemberItemProvider resourceProfileMemberItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.ResourceProfileMember}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createResourceProfileMemberAdapter() {
		if (resourceProfileMemberItemProvider == null) {
			resourceProfileMemberItemProvider = new ResourceProfileMemberItemProvider(this);
		}

		return resourceProfileMemberItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileReference} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProfileReferenceItemProvider profileReferenceItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileReference}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createProfileReferenceAdapter() {
		if (profileReferenceItemProvider == null) {
			profileReferenceItemProvider = new ProfileReferenceItemProvider(this);
		}

		return profileReferenceItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.StructuralFeatureProfile} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected StructuralFeatureProfileItemProvider structuralFeatureProfileItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.StructuralFeatureProfile}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createStructuralFeatureProfileAdapter() {
		if (structuralFeatureProfileItemProvider == null) {
			structuralFeatureProfileItemProvider = new StructuralFeatureProfileItemProvider(this);
		}

		return structuralFeatureProfileItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.ViolationWaiver} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ViolationWaiverItemProvider violationWaiverItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.ViolationWaiver}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createViolationWaiverAdapter() {
		if (violationWaiverItemProvider == null) {
			violationWaiverItemProvider = new ViolationWaiverItemProvider(this);
		}

		return violationWaiverItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileEnvelopeConstraint} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProfileEnvelopeConstraintItemProvider profileEnvelopeConstraintItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileEnvelopeConstraint}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createProfileEnvelopeConstraintAdapter() {
		if (profileEnvelopeConstraintItemProvider == null) {
			profileEnvelopeConstraintItemProvider = new ProfileEnvelopeConstraintItemProvider(this);
		}

		return profileEnvelopeConstraintItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileEqualityConstraint} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProfileEqualityConstraintItemProvider profileEqualityConstraintItemProvider;

	/**
	 * This creates an adapter for a {@link gov.nasa.ensemble.core.plan.resources.profile.ProfileEqualityConstraint}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createProfileEqualityConstraintAdapter() {
		if (profileEqualityConstraintItemProvider == null) {
			profileEqualityConstraintItemProvider = new ProfileEqualityConstraintItemProvider(this);
		}

		return profileEqualityConstraintItemProvider;
	}

	/**
	 * This returns the root adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public ComposeableAdapterFactory getRootAdapterFactory() {
		return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
	}

	/**
	 * This sets the composed adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) {
		this.parentAdapterFactory = parentAdapterFactory;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isFactoryForType(Object type) {
		return supportedTypes.contains(type) || super.isFactoryForType(type);
	}

	/**
	 * This implementation substitutes the factory itself as the key for the adapter.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter adapt(Notifier notifier, Object type) {
		return super.adapt(notifier, this);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object adapt(Object object, Object type) {
		if (isFactoryForType(type)) {
			Object adapter = super.adapt(object, type);
			if (!(type instanceof Class<?>) || (((Class<?>)type).isInstance(adapter))) {
				return adapter;
			}
		}

		return null;
	}

	/**
	 * This adds a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void addListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.addListener(notifyChangedListener);
	}

	/**
	 * This removes a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void removeListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.removeListener(notifyChangedListener);
	}

	/**
	 * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void fireNotifyChanged(Notification notification) {
		changeNotifier.fireNotifyChanged(notification);

		if (parentAdapterFactory != null) {
			parentAdapterFactory.fireNotifyChanged(notification);
		}
	}

	/**
	 * This disposes all of the item providers created by this factory. 
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void dispose() {
		if (profileEffectItemProvider != null) profileEffectItemProvider.dispose();
		if (profileEnvelopeConstraintItemProvider != null) profileEnvelopeConstraintItemProvider.dispose();
		if (profileEqualityConstraintItemProvider != null) profileEqualityConstraintItemProvider.dispose();
		if (profileMemberItemProvider != null) profileMemberItemProvider.dispose();
		if (resourceProfileMemberItemProvider != null) resourceProfileMemberItemProvider.dispose();
		if (profileReferenceItemProvider != null) profileReferenceItemProvider.dispose();
		if (structuralFeatureProfileItemProvider != null) structuralFeatureProfileItemProvider.dispose();
		if (violationWaiverItemProvider != null) violationWaiverItemProvider.dispose();
	}

}
